#include<stdio.h>
#include<string.h>
#include<fcntl.h>

#define FILEPATH "/home/xilinx-qt/code/HelloWord/helloword/test"
#define FLAGS    O_CREAT | O_WRONLY | O_TRUNC
#define MODE     S_IRWXU
#define SIZE     200

int main(int argc,char* argv[])
{
    int count = 0;
    int fd = 0;
    char data[SIZE];
    const char* pathname = FILEPATH;
    printf("%s\n",pathname);
    fd = open(pathname,FLAGS,MODE);
    if(fd == -1)
    {
        printf("open file failed\n");
        return 0;
    }
    printf("open file success\n");
    printf("请输入字符串：\n");
    scanf("%s",data);
    count = strlen(data);
    printf("show data:%s\n",data);
    printf("data length is:%d\n",count);
    if(write(fd,data,count) == -1)
    {
        printf("write data failed!\n");
        return 0;
    }
    printf("write data success!\n");
    close(fd);
    fd = open(pathname,O_RDONLY);
    char content[100];
    read(fd,content,count);
    printf("test content is:%s\n",content);
    printf("content size is %d\n",(int)strlen(content));
    close(fd);


    return 0;
}
